<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <!-- 搜索输入框 -->
      <div style="margin-top: 15px">
        <el-input
          style="width: 500px"
          placeholder="请输入内容"
          v-model="input2"
        >
          <el-button
            @click="searchOrders"
            slot="append"
            icon="el-icon-search"
          ></el-button>
        </el-input>
      </div>
      <!-- 订单数据列表 -->
      <el-table
        ref="singleTable"
        :data="list"
        border
        highlight-current-row
        style="width: 100%"
      >
        <el-table-column label="序号" type="index" width="50">
          <template slot-scope="{ $index }">
            {{ obj.pagesize * (obj.pagenum - 1) + $index + 1 }}
          </template>
        </el-table-column>
        <el-table-column property="order_number" label="订单编号" width="500">
        </el-table-column>
        <el-table-column property="order_price" label="订单价格" width="250">
        </el-table-column>
        <el-table-column property="pay_status" label="是否付款" width="200">
          <template slot-scope="{ row }">
            <el-tag v-if="row.pay_status == '0'" type="danger">未付款</el-tag>
            <el-tag v-else type="success">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column property="is_send" label="是否发货" width="200">
        </el-table-column>
        <el-table-column property="create_time" label="下单时间" width="200">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="{ row }">
            <el-button
              @click="editHandle(row)"
              type="primary"
              icon="el-icon-edit"
              size="mini"
            ></el-button>
            <el-button
              @click="location(row.order_id)"
              type="success"
              icon="el-icon-location"
              size="mini"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="obj.pagenum"
        :page-sizes="[5, 10, 15]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
      <!-- 编辑对话框 -->
      <el-dialog title="修改地址" :visible.sync="dialogTableVisible1">
        <el-form :model="form" :rules="rules2">
          <el-form-item
            label="活动区域"
            :label-width="formLabelWidth"
            prop="place"
          >
            <el-cascader
              size="large"
              :options="options"
              v-model="provinces"
              style="width: 820px"
              @change="handleChange"
              placeholder="请选择"
            ></el-cascader>
          </el-form-item>
          <el-form-item
            label="活动名称"
            :label-width="formLabelWidth"
            prop="address"
          >
            <el-input
              style="width: 820px"
              v-model="form.name"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogTableVisible1 = false">取 消</el-button>
          <el-button type="primary" @click="dialogTableVisible1 = false">确定</el-button
          >
        </div>
      </el-dialog>
      <!-- 物流进度 -->
      <el-dialog title="物流进度" :visible.sync="dialogTableVisible">
        <el-timeline :reverse="false">
          <el-timeline-item
            v-for="(item, index) in places"
            :key="index"
            :timestamp="item.time"
          >
            {{ item.context }}
          </el-timeline-item>
        </el-timeline>
      </el-dialog>
    </el-card>
  </div>
</template>
<script>
import { getOrdersAPI, getKuaidiAPI } from '@/api/orders'
import { regionData } from "element-china-area-data";
export default {
  name: '',
  data () {
    return {
      obj: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      input2: '',
      list: [],
      total: 0,
      places: [],
      reverse: true,
      dialogTableVisible: false,
      dialogTableVisible1: false,
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      formLabelWidth: '90px',
      rules2: {
        place: [
          { required: true, message: '用户名不能为空', trigger: 'blur' },
        ],
        address: [
          { required: true, message: '密码不能为空', trigger: 'blur' },
          // { validator: validatePass2, trigger: 'blur' }
          { min: 5, max: 11, message: '长度在5到11个字符', trigger: ['blur', 'change'] }
        ]
      },
      options: regionData,
      provinces: [],
    }
  },
  created () {
    this.getOrders()
  },
  computed: {
  },
  methods: {
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`);
      this.obj.pagesize = val
      this.getOrders()
    },
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`);
      this.obj.pagenum = val
      this.getOrders()
    },
    async getOrders () {
      const res = await getOrdersAPI(this.obj)
      // console.log(res);
      this.list = res.data.goods
      this.total = res.data.total
    },
    async searchOrders () {
      console.log(this.input2);
      this.obj.query = this.input2
      this.obj.pagenum = 1
      const res = await getOrdersAPI(this.obj)
      console.log(res);
      this.getOrders()
    },
    editHandle () {
      this.dialogTableVisible1 = true
    },
    async location (id) {
      this.dialogTableVisible = true
      console.log(id);
      const res = await getKuaidiAPI(id)
      // console.log(res);
      this.places = res.data
      console.log(this.places, 'places');
    },
    handleChange (e) {
      console.log(e, "所选code值");
    },
  }
}
</script>
<style lang='less'  scoped>
.el-form {
  width: 90%;
}
.box-card {
  margin-top: 15px;
  .el-input {
    // width: 500px;
    margin-right: 20px;
  }
}
</style>
